#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "list.h"

struct num
{
	int i;
	struct list_head list;
};


int main()
{
	LIST_HEAD(test_list);

	int i;
	struct num *num;
	struct num *num1;

	srand((unsigned) time(NULL));
	printf("\n insert 50 elments to linked list.\n\n");
	for (i = 1; i <= 50; i++)
	{
		num = (struct num *) malloc(sizeof(struct num));
		num->i = i;
		list_head_tail(&num->list, &test_list);
	}
	i = 0;
	printf("out put linked list:\n");
	list_for_each_entry(num, &test_list, list)
	{
		printf("%3d", num->i);
		if (0 == (i + 1) % 10)
		{
			printf("\n");
		}
		i++;
	}

	list_for_each_entry_safe(num, num1, &test_list, list)
	{
		list_del(&num->list);
		free(num);
	}

	if (list_empty(&test_list))
	{
		printf("\nrelease linked list success.\n\n");
	}
	return 0;
}
